package com.caishi.lkx.user.api;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.caishi.lkx.common.AdminBaseApi;
import com.caishi.lkx.user.model.PositionModel;
import com.caishi.lkx.user.service.IPositionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;

/**
 * @author by keray
 * date:2021/4/20 4:24 下午
 */
@RestController
@RequestMapping("/user/cu/admin/position")
public class PositionApi extends AdminBaseApi<IPositionService, PositionModel, Long> {

    @Resource
    private IPositionService positionService;

    @Override
    public IPositionService loadService() {
        return positionService;
    }

    @GetMapping("/owner-list")
    public Collection<PositionModel> userNextLevelPosition() {
        return positionService.userNextLevelPosition(userContext.currentUserId());
    }

    @Override
    protected LambdaQueryWrapper<PositionModel> baseWrapper(PositionModel model, JSONObject otherParam) {
        return super.baseWrapper(model.clearEmptyStringField("name"), otherParam)
                .like(StrUtil.isNotBlank(model.getName()), PositionModel::getName, model.getName());
    }
}
